package service;

import service.impl.FormModelSubmitHandler;
import service.impl.FormPreviewSubmitHandler;
import java.util.HashMap;
import java.util.Map;

//@Component
public class FormSubmitHandlerFactory  {

    private static final
    Map<String, FormSubmitHandler> FORM_SUBMIT_HANDLER_MAP = new HashMap<>(8);



    /**
     * 根据提交类型获取对应的处理器
     *
     * @param submitType 提交类型
     * @return 提交类型对应的处理器
     */
    public FormSubmitHandler getHandler(String submitType) {
        return FORM_SUBMIT_HANDLER_MAP.get(submitType);
    }


    public void init() {
        // 将 Spring 容器中所有的 FormSubmitHandler 注册到 FORM_SUBMIT_HANDLER_MAP
        FormSubmitHandler modelSubmitHandler = new FormModelSubmitHandler();
        FORM_SUBMIT_HANDLER_MAP.put(modelSubmitHandler.getSubmitType(), modelSubmitHandler);
        FormSubmitHandler previewSubmitHandler = new FormPreviewSubmitHandler();
        FORM_SUBMIT_HANDLER_MAP.put(previewSubmitHandler.getSubmitType(), previewSubmitHandler);
    }

}